cmake_minimum_required(VERSION 3.8)
project(hudar)



# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(spdlog REQUIRED)
find_package(fmt REQUIRED)

find_package(std_msgs REQUIRED)
find_package(OpenCV REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(cv_bridge REQUIRED)
find_package(Eigen3 REQUIRED)
find_package(PCL REQUIRED)
find_package(image_transport REQUIRED)
find_package(PkgConfig REQUIRED)
find_package(rm_msg REQUIRED)   
pkg_check_modules(PCAP REQUIRED libpcap)

# Cuda Setting
find_package(CUDA REQUIRED)
option(CUDA_USE_STATIC_CUDA_RUNTIME OFF)
set(CUDA_GEN_CODE "-gencode=arch=compute_75,code=sm_75")
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS}  -std=c++17 -O3 -Xcompiler -fPIC -g -w ${CUDA_GEN_CODE}")


if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  # the following line skips the linter which checks for copyrights
  # comment the line when a copyright and license is added to all source files
  set(ament_cmake_copyright_FOUND TRUE)
  # the following line skips cpplint (only works in a git repo)
  # comment the line when this package is in a git repo and when
  # a copyright and license is added to all source files
  set(ament_cmake_cpplint_FOUND TRUE)
  ament_lint_auto_find_test_dependencies()
endif()

include_directories(${EIGEN3_INCLUDE_DIRS}
${PCAP_INCLUDE_DIRS}
${PCL_LIBRARY_DIRS}

  /opt/MVS/include
  /usr/local/cuda/include
  /usr/local/TensorRT-10.0.1.6/include
  
)



include_directories(
  # include
  # pcl_conversions目录
  ThirdParty/
  /opt/ros/humble/include/
  /opt/ros/humble/include/message_filters
  /opt/ros/humble/include/pcl_msgs
  /opt/ros/humble/include/image_transport
  src/RadarClass/Radar/include
)



set(radar_source 
  src/RadarClass/TRTInference/TRTInfer/CUDA/preprocess.cu
  src/RadarClass/TRTGenerator/TRTGenerator/src/Generator.cpp
  src/RadarClass/Common/src/algorithm.cpp
  src/RadarClass/Detectors/src/CarDetector.cpp
  src/RadarClass/Detectors/src/ArmorDetector.cpp
  src/RadarClass/TRTInference/TRTInfer/src/Inference.cpp
  src/main.cpp
  src/RadarClass/Radar/src/Radar.cpp
  src/RadarClass/Camera/Camera.cpp
  src/RadarClass/Common/src/algorithm.cpp
  src/RadarClass/Detectors/src/depthProcesser.cpp
  src/RadarClass/Logger/src/Logger.cpp
  src/RadarClass/Location/src/MapMapping.cpp
  src/RadarClass/Location/src/location.cpp
  ThirdParty/Json/jsoncpp.cpp
  src/RadarClass/Camera/VideoRecorder.cpp
)




link_directories(
    ${PCL_LIBRARY_DIRS}
    /opt/MVS/lib/64/
    /usr/local/cuda/lib64/
    /usr/local/TensorRT-10.0.1.6/lib
)

add_definitions(${PCL_DEFINITIONS})



cuda_add_executable(radar ${radar_source}
)
set_target_properties(radar PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
ament_target_dependencies(radar rclcpp std_msgs sensor_msgs OpenCV cv_bridge rm_msg)

add_executable(gui src/RadarClass/GUI/gui.cpp)
ament_target_dependencies(gui rclcpp std_msgs sensor_msgs OpenCV cv_bridge rm_msg)

target_link_libraries(radar

  ${CUDA_LIBRARIES}
  ${CUDA_cudadevrt_LIBRARY}

  ${PCL_COMMON_LIBRARIES} ${PCL_IO_LIBRARIES} ${PCL_LIBRARIES}
  -lpcap
  pthread
  -lMvCameraControl
  spdlog
  Eigen3::Eigen
  fmt::fmt-header-only


  cudart
  nvonnxparser
  libnvinfer.so
  libnvinfer_plugin.so
  -lpthread -lm
)


install(TARGETS
  radar
  gui
  DESTINATION lib/${PROJECT_NAME}
)

install(
  DIRECTORY launch
  DESTINATION share/${PROJECT_NAME}
)
ament_package()


macro(remove_warnings)
  add_definitions(-Wno-deprecated-declarations
    -Wno-unused-but-set-variable
    -Wno-unused-variable)
endmacro()

remove_warnings()